package com.osfw.framework.directive;


import cn.dev33.satoken.stp.StpUtil;
import com.osfw.framework.utils.StringUtils;
import com.osfw.system.entity.manage.SysUser;
import com.osfw.system.service.config.ISysConfigService;
import com.osfw.system.service.manage.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;


/**
 * 统一基本信息获取
 */
@Service("common")
public class CommonService {

    @Autowired
    private ISysUserService userService;

    /**
     * 判断是否超级管理员
     */
    public boolean isAdministrator() {
        if (StpUtil.isLogin()) {
            SysUser user = StpUtil.getSession().getModel("user", SysUser.class);
            return user.isAdmin();
        }
        return false;
    }

    /**
     * 获取当前用户ID
     */
    public Long getUserId() {
        if (StpUtil.isLogin()) {
            return StpUtil.getLoginIdAsLong();
        }
        return null;
    }

    /**
     * 获取当前用户Name
     *
     * @param
     * @return String
     */
    public String getUserName() {
        if (StpUtil.isLogin()) {
            SysUser user = StpUtil.getSession().getModel("user", SysUser.class);
            return user.getUserName();
        }
        return StringUtils.EMPTY;
    }

    /**
     * 判断是否系统管理员
     *
     * @return java.lang.String
     */
    public boolean isAdmin() {
        if (StpUtil.isLogin()) {
            SysUser user = StpUtil.getSession().getModel("user", SysUser.class);
            return user.isAdmin();
        }
        return false;
    }

    /**
     * 判断是否系统管理员
     *
     * @return java.lang.String
     */
    public List<SysUser> getUserList() {
        if (StpUtil.isLogin()) {
            SysUser user = StpUtil.getSession().getModel("user", SysUser.class);
            SysUser sysUser = new SysUser();
            sysUser.setDeptId(user.getDeptId());
            return userService.selectUserList(sysUser);
        }
        return Collections.EMPTY_LIST;
    }

}
